package org.practice.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Web容器启动时，初始化Spring IOC容器（ApplicationContext），并调用setter方法注入
 * 只能在web环境中使用，比如(Action中获取service等，单独运行测试报空指针)
 * @author jack
 */
public class ServiceProvider implements ApplicationContextAware{
	private static ApplicationContext ctx;

	public static ApplicationContext getBeanFactory() {
		return ctx;
	}
	
	public void setApplicationContext(ApplicationContext ctx) {
		ServiceProvider.ctx = ctx;
	}

	public static Object getService(String name) {
		return ctx.getBean(name);
	}
	
}
